package com.example.lemoncommon.entity;

public class Result<T> {

    /**
     * 响应状态码
     */
    private String code;

    /**
     * 响应消息
     */
    private String msg;
    /**
     * 响应数据
     */
    private T data;

    private long time;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Result() {
        this.time = System.currentTimeMillis();
    }

    public Result(String code, String msg) {
        this.code = code;
        this.msg = msg;
        this.time = System.currentTimeMillis();
    }

    public long getTime() {
        return time;
    }

    public void setTime(long time) {
        this.time = time;
    }

    public Result(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.time = System.currentTimeMillis();
    }

    /**
     * 成功 返回默认成功信息
     *
     * @return
     */
    public static<T> Result<T> SUCCESS() {
        return new Result<T>("200",  "操作成功", null);
    }

    /**
     * 成功 返回（data数据）成功信息
     *
     * @param data
     * @return
     */
    public static<T> Result<T> SUCCESS(T data) {
        return new Result<T>("200", "请求成功", data);
    }

    /**
     * 成功 返回自定义（消息、data数据）成功信息
     *
     * @param msg
     * @param data
     * @return
     */
    public static<T> Result<T> SUCCESS(String msg, T data) {
        return new Result<T>("200", msg, data);
    }

    /**
     * 失败 返回默认失败信息
     *
     * @return
     */
    public static<T> Result<T> ERROR() {
        return new Result<T>("-1", "操作失败", null);
    }

    /**
     * 失败 返回自定义（消息）失败信息
     *
     * @param msg
     * @return
     */
    public static<T> Result<T> ERROR(String msg) {
        return new Result<T>("-1", msg, null);
    }

    /**
     * 失败 返回自定义（消息、状态码）失败信息
     *
     * @param code
     * @param msg
     * @return
     */
    public static<T> Result<T> ERROR(String code, String msg) {
        return new Result<T>(code, msg, null);
    }
}